#!/bin/bash
source /etc/profile
source activate python27

mkdir -p /home/marvin/daily_job/logs/`date +%Y-%m-%d`

# 先校验中间库数据是否完整
python /home/marvin/daily_job/py_job/sqlserver_check.py >>/home/marvin/daily_job/logs/`date +%Y-%m-%d`/sqlserver_check.log 2>&1
consistence=1
t=1

while [[ $consistence != 0 && $t != 0 ]]
do
consistence=`cat /home/marvin/daily_job/py_job/consistence`
if [[ $consistence == 0 ]];then
  echo 1
else
  echo 'sleep for data...'
  sleep 1m
fi
if [[ $(date +%H) == '03' ]];then
  t=0
fi
python /home/marvin/daily_job/py_job/sqlserver_check.py >>/home/marvin/daily_job/logs/`date +%Y-%m-%d`/sqlserver_check.log 2>&1

done

echo "------------------------------------------------------------------------"
start=`date +%s`
echo "开始数据抽取，start dailysqoop"`date +"%Y-%m-%d %H:%M"`
sh /home/marvin/daily_job/sqoop/dailysqoop.sh >>/home/marvin/daily_job/logs/`date +%Y-%m-%d`/dailysqoop.loglog 2>&1
dailysqoop_end=`date +%s`
usetime=`expr $dailysqoop_end - $start`
echo "数据抽取结束，end dailysqoop,usetime:$usetime"

cd /home/marvin/hive-1.1.0-cdh5.6.0

echo "------------------------------------------------------------------------"
start=`date +%s`
echo "开始执行hql，start dailyhql"`date +"%Y-%m-%d %H:%M"`
sh /home/marvin/daily_job/hive/dailyhql.sh >>/home/marvin/daily_job/logs/`date +%Y-%m-%d`/dailyhql.loglog 2>&1
end=`date +%s`
usetime=`expr $end - $start`
echo "hql结束，end dailyhql,usetime:$usetime"

echo "------------------------------------------------------------------------"
start=`date +%s`
echo "开始执行向mysql导数据，start hive to mysql"`date +"%Y-%m-%d %H:%M"`
sh /home/marvin/daily_job/delete_or_truncate/dailytruncate.sh >>/home/marvin/daily_job/logs/`date +%Y-%m-%d`/dailytruncate.loglog 2>&1
sh /home/marvin/daily_job/delete_or_truncate/dailydelete.sh >>/home/marvin/daily_job/logs/`date +%Y-%m-%d`/dailytruncate.loglog 2>&1
sh /home/marvin/daily_job/sqoop/dailyhqlsqoop.sh >>/home/marvin/daily_job/logs/`date +%Y-%m-%d`/dailyhqlsqoop.loglog 2>&1
#sh /home/marvin/daily_job/delete_or_truncate/dailydelete.sh >>/home/marvin/dailynoon_job/logs/`date +%Y-%m-%d`/dailydelete.loglog 2>&1
#发送邮件
python /home/marvin/daily_job/py_job/result_check.py >>/home/marvin/daily_job/logs/`date +%Y-%m-%d`/result_check.log 2>&1
python /home/marvin/daily_job/py_job/chainratio.py >>/home/marvin/daily_job/logs/`date +%Y-%m-%d`/chainratio.log 2>&1
python /home/marvin/daily_job/py_job/huanbi_mail.py >>/home/marvin/daily_job/logs/`date +%Y-%m-%d`/huanbi_mail.log 2>&1
python /home/marvin/daily_job/py_job/sqlserver_check_mail.py >>/home/marvin/daily_job/logs/`date +%Y-%m-%d`/sqlserver_check_mail.log 2>&1
end=`date +%s`
usetime=`expr $end - $start`
echo "hive to mysql结束,end,usetime:$usetime ...."`date +"%Y-%m-%d %H:%M"`
